import Api from '@core/http/decorates/api';
import { IList } from '@core/http/IList';
import { AxiosInstance } from 'axios';
import { GetNoteListRes } from './models/GetNoteListRes';
import { InsertNoteData } from './models/InsertNoteData';

@Api({ prefix: 'note' })
export class Note {
  private readonly http: AxiosInstance;

  /**
   * 获得全部笔记
   *
   * @param {number} pageIndex
   * @param {number} pageSize
   * @param {string} searchTerm
   * @return {*}
   * @memberof Note
   */
  async getNoteList(
    pageIndex: number,
    pageSize: number,
    userId: string,
    title?: string,
  ) {
    return (
      await this.http.get<IList<GetNoteListRes>>('getNoteList', {
        params: {
          userId,
          title,
          pageSize,
          pageIndex,
        },
      })
    ).data;
  }

  /**
   * 插入note
   *
   * @param {GetNoteListRes} data
   * @return {*}
   * @memberof Note
   */
  async insertNote(data: InsertNoteData) {
    return (await this.http.post('insertNote', data)).data;
  }

  /**
   * 获得单个笔记
   *
   * @param {string} id
   * @return {*}
   * @memberof Note
   */
  async getNoteDetail(id: string) {
    return (
      await this.http.get<GetNoteListRes>('getNoteDetail', {
        params: {
          id,
        },
      })
    ).data;
  }

  /**
   * 删除
   *
   * @param {string} id
   * @return {*}
   * @memberof Note
   */
  async deleteNote(id: string) {
    return (
      await this.http.post<GetNoteListRes>('deleteNote', {
        id,
      })
    ).data;
  }
}
